package com.myk.game.sumeru.game;

import java.util.ArrayList;
import java.util.List;

public class Map {

    private final Grid[][] grids;

    public Map() {
        int[][] gridData = new int[][]{
                {9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9},
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0},
                {0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0},
                {0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1}
        };
        int row = gridData.length;
        int col = gridData[0].length;
        grids = new Grid[row][col];
        for (int y = 0; y < row; y++) {
            for (int x = 0; x < col; x++) {
                grids[y][x] = new Grid(gridData[y][x], x, y);
            }
        }
    }

    /**
     * 获取地图的行数
     */
    public int getRowCount() {
        return grids.length;
    }

    /**
     * 获取地图的列数
     */
    public int getColumnCount() {
        return grids[0].length;
    }

    /**
     * 获取格子源数据
     */
    public Grid[][] getGrids(){
        return grids;
    }

    /**
     * 获取水源格子
     */
    public List<Grid> getLakeGrids() {
        List<Grid> lakeGrids = new ArrayList<>();
        for (Grid[] lang : grids) {
            for (Grid grid : lang) {
                if (grid.getType() == 5) {
                    lakeGrids.add(grid);
                }
            }
        }
        return lakeGrids;
    }

}
